#include "imgui/gut/Editor.h"

bool ImGui::Gut::Editor::Show(const Ogl::Gut::Texture2D *tex, ImVec2 sz)
{
    ImGui::Image(reinterpret_cast<ImTextureID>(tex->m_Id), ImVec2(tex->m_ImageSize.x, tex->m_ImageSize.y));
    return false;
}

void ImGui::Gut::Editor::Framebuffer(const Ogl::Gut::Texture2D *tex, ImVec2 sz, ImVec2 uv0, ImVec2 uv1)
{
    ImGui::Image(reinterpret_cast<ImTextureID>(tex->m_Id), sz, uv0, uv1);
}

void ImGui::Gut::Editor::AddFramebuffer(const Ogl::Gut::Texture2D *tex, ImVec2 uv0, ImVec2 uv1)
{
    ImDrawList *drawList = ImGui::GetWindowDrawList();
    auto wPos = ImGui::GetWindowPos();
    auto wsz = ImGui::GetWindowSize();
    drawList->AddImage(reinterpret_cast<ImTextureID>(tex->m_Id), wPos, ImVec2(wPos.x + wsz.x, wPos.y + wsz.y), uv0, uv1);
}

bool ImGui::Gut::Editor::MousePos(float &xa, float &ya)
{
    ImGuiIO &io = ImGui::GetIO();
    ImVec2 mousePos = io.MousePos;

    ImVec2 windowPos = ImGui::GetWindowPos();
    ImVec2 windowSize = ImGui::GetWindowSize();
    xa = (float)(mousePos.x - windowPos.x) / (float)windowSize.x;
    ya = (float)(mousePos.y - windowPos.y) / (float)windowSize.y;

    return xa > 0.0f && xa < 1.0f && xa > .0f && xa < 1.0f;
}